Hibernate Exception, what wrong ? [[Exception in thread "main" org.hibernate.InvalidMappingException

Posted by user195970 on Stack Overflow See other posts from Stack Overflow or by user195970
Published on 2009-10-24T20:03:24Z Indexed on 2010/04/12 4:03 UTC
Read the original article Hit count: 1484

Filed under:
|

I use netbean 6.7.1 to write "hello world" witch hibernate, but I get some errors, plz help me, thank you very much.

my exception

init:
deps-module-jar:
deps-ear-jar:
deps-jar:
Copying 1 file to F:\Documents and Settings\My Dropbox\DropboxNetBeanProjects\loginspring\build\web\WEB-INF\classes
compile-single:
run-main:
Oct 25, 2009 2:44:05 AM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.5
Oct 25, 2009 2:44:05 AM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Oct 25, 2009 2:44:05 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
Oct 25, 2009 2:44:05 AM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Oct 25, 2009 2:44:05 AM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Oct 25, 2009 2:44:05 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Oct 25, 2009 2:44:06 AM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : hibernate/Tbluser.hbm.xml
Oct 25, 2009 2:44:06 AM org.hibernate.util.XMLHelper$ErrorLogger error
SEVERE: Error parsing XML: XML InputStream(1) Document is invalid: no grammar found.
Oct 25, 2009 2:44:06 AM org.hibernate.util.XMLHelper$ErrorLogger error
SEVERE: Error parsing XML: XML InputStream(1) Document root element "hibernate-mapping", must match DOCTYPE root "null".
Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource hibernate/Tbluser.hbm.xml
        at org.hibernate.cfg.Configuration.addResource(Configuration.java:569)
        at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1587)
        at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
        at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
        at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
        at hibernate.CreateTest.main(CreateTest.java:22)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from invalid mapping
        at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:502)
        at org.hibernate.cfg.Configuration.addResource(Configuration.java:566)
        ... 7 more
Caused by: org.xml.sax.SAXParseException: Document is invalid: no grammar found.
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:250)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:626)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3095)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:921)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
        at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
        at org.dom4j.io.SAXReader.read(SAXReader.java:465)
        at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:499)
        ... 8 more
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)

hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernate</property>
    <property name="hibernate.connection.username">root</property>
  </session-factory>
</hibernate-configuration>

Tbluser.hbm.xml

 <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Oct 25, 2009 2:37:30 AM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
    <class name="hibernate.Tbluser" table="tbluser" catalog="hibernate">
        <id name="userId" type="java.lang.Integer">
            <column name="userID" />
            <generator class="identity" />
        </id>
        <property name="username" type="string">
            <column name="username" length="50" />
        </property>
        <property name="password" type="string">
            <column name="password" length="50" />
        </property>
        <property name="email" type="string">
            <column name="email" length="50" />
        </property>
        <property name="phone" type="string">
            <column name="phone" length="50" />
        </property>
        <property name="groupId" type="java.lang.Integer">
            <column name="groupID" />
        </property>
    </class>
</hibernate-mapping>

Tbluser.java

  package hibernate;
// Generated Oct 25, 2009 2:37:30 AM by Hibernate Tools 3.2.1.GA



    /**
     * Tbluser generated by hbm2java
     */
    public class Tbluser  implements java.io.Serializable {


         private Integer userId;
         private String username;
         private String password;
         private String email;
         private String phone;
         private Integer groupId;

        public Tbluser() {
        }

        public Tbluser(String username, String password, String email, String phone, Integer groupId) {
           this.username = username;
           this.password = password;
           this.email = email;
           this.phone = phone;
           this.groupId = groupId;
        }

        public Integer getUserId() {
            return this.userId;
        }

        public void setUserId(Integer userId) {
            this.userId = userId;
        }
        public String getUsername() {
            return this.username;
        }

        public void setUsername(String username) {
            this.username = username;
        }
        public String getPassword() {
            return this.password;
        }

        public void setPassword(String password) {
            this.password = password;
        }
        public String getEmail() {
            return this.email;
        }

        public void setEmail(String email) {
            this.email = email;
        }
        public String getPhone() {
            return this.phone;
        }

        public void setPhone(String phone) {
            this.phone = phone;
        }
        public Integer getGroupId() {
            return this.groupId;
        }

        public void setGroupId(Integer groupId) {
            this.groupId = groupId;
        }


}

© Stack Overflow or respective owner

Related posts about java

Related posts about hibernate